package com.dyna.digit.process.strategy;

import cn.hutool.core.lang.Assert;
import com.dyna.enums.DigitFlowStatusEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhoucaiwang
 * @date 2023/11/19
 */
@Slf4j
public class DigitFlowFactory {

    /**
     * 初始化流程
     */
    private static final Map<Integer, AbstractFlowHandler> STRATEGY_MAP = new HashMap<>(16);

    /**
     * 注册流程
     */
    public static void register(DigitFlowStatusEnum digitFlowStatusEnum, AbstractFlowHandler strategy) {
        log.info("工厂流程环节初始化: ===》 DigitFlowFactory register:【" + digitFlowStatusEnum.getStatus() + "】 strategy: 【" + digitFlowStatusEnum.getDesc() + "】");
        STRATEGY_MAP.put(digitFlowStatusEnum.getStatus(), strategy);
    }

    /**
     * 获取策略
     */
    public static AbstractFlowHandler getStrategy(Integer flowCode) {
        AbstractFlowHandler flowHandler = STRATEGY_MAP.get(flowCode);
        Assert.notNull(flowHandler, "未找到对应流程策略");
        return flowHandler;
    }

}
